<template>
  <div class="questionDetail">
    <question-top :itemInfo="itemInfo"></question-top>
    <div class="detail-box">
      <div class="question-wrap">
        <div class="question-wrap-item">
          <div class="question-wrap-item-con">
            <span class="icon icon_ask"></span>
            <span class="ask-text bold">{{ questionDetail.comment }}</span>
          </div>
          <div class="question-wrap-item-time">
            <span>{{ questionDetail.create_time }}</span>
          </div>
        </div>
        <div class="question-wrap-item noPdTop">
          <div class="question-wrap-item-con">
            <span class="icon icon_answer"></span>
            <span class="ask-text bold">共{{ user_answers.length || 0 }}个回答</span>
          </div>
          <comment-user :commentUser="user_answers"></comment-user>
        </div>
      </div>
    </div>
    <div class="comment-bottom">
      <div class="input-area">
        <input type="text" v-model="comment" placeholder="回答小伙伴的提问">
      </div>
      <div class="btn-area">
        <van-button round class="btn" @click="handleClickAnswer">回答</van-button>
      </div>
    </div>
    <my-answer></my-answer>
  </div>
</template>

<script>
  /**
   * @Author: yqe@360shop.cn
   * @Date: 2020-07-15 11:18:14
   * @Last Modified by: yqe@360shop.cn
   * @Last Modified time: 2020-07-15 11:18:14
   */
  import Vue from 'vue'
  import myAnswer from '../components/myAnswer'
  import questionTop from '../components/questionTop'
  import commentUser from '../components/commentUser'
  import { questionDetail, answerQuestion } from '@/api/item/question'
  export default Vue.extend({
    name: 'index',
    components: {
      questionTop,
      commentUser,
      myAnswer
    },
    data() {
      return {
        itemInfo: {},
        questionDetail: {}, // 问题信息
        comment: '',
        user_answers: [] // 回答
      }
    },
    methods: {
      /**
       * 问题详情
       */
      questionDetailFn() {
        const param = {
          id: this.$route.query.questionId,
          page: 1,
          per_page: 100
        }
        questionDetail(param).then(res => {
          if (res.status == 1) {
            this.questionDetail = res.data.question
            this.user_answers = res.data.user_answers
            const itemInfo = {
              img: res.data.question.item_img,
              title: res.data.question.item_title,
              questionNum: res.data.question_num
            }
            this.itemInfo = itemInfo
          }
        })
      },
      /**
       * 初始化
       */
      init() {
        this.questionDetailFn()
      },
      /**
       * 回答
       */
      handleClickAnswer() {
        const param = {
          type_id: this.$route.query.questionId,
          comment: this.comment
        }
        if (!param.comment) {
          this.$Error('回答不能为空！')
          return false
        }
        answerQuestion(param).then(res => {
          if (res.status == 1) {
            this.$Error('回答成功！')
            this.comment = ''
            this.init()
          } else {
            // TODO 增加提示
            this.$Error(res.msg)
          }
        })
      }
    },
    mounted() {
      this.init()
    }
  })
</script>

<style lang="scss">
  // TODO 小程序处理
  .miniprogram-root {
    .van-button--normal {
      font-size: 28px;
    }
  }
  .questionDetail{
    .detail-box{
      padding-top: 20px;
      padding-bottom: 120px;
      .question-wrap{
        border-radius:20px;
        overflow: hidden;
        width:700px;
        margin: 0 auto;
        &-item{
          padding: 30px 25px;
          background:rgba(255,255,255,1);
          &.noPdTop{
            padding-top: 0;
          }
          &-con{
            line-height: 40px;
            // height: 40px;
            margin-bottom: 16px;
            font-size: 0;
            .icon{
              display: inline-block;
              width: 40px;
              height: 40px;
              vertical-align: top;
              margin-right: 20px;
              &.icon_ask{
                background:url(https://img.wifenxiao.com/h5-wfx/images/item/detail/icon_ask.png) bottom no-repeat;
                background-size:100% 100%;
              }
              &.icon_answer{
                background:url(https://img.wifenxiao.com/h5-wfx/images/item/detail/icon_answer.png) bottom no-repeat;
                background-size:100% 100%;
              }
            }
            .ask-text{
              color: #333;
              font-size: 26px;
              &.bold{
                font-weight: bold;
              }
            }
          }
          &-time{
            border-bottom: 2px solid #EDEDED;
            font-size: 22px;
            color: #999999;
            padding-left: 60px;
            padding-bottom: 39px;
          }
          .answer-wrap{
            &-item{
              padding: 30px 0;
              border-bottom: 1px solid #EDEDED;
              &:last-child{
                border-bottom: none;
              }
              .answer-user{
                font-size: 0;
                &-left{
                  width: 70px;
                  height: 70px;
                  display: inline-block;
                  vertical-align: top;
                  border-radius: 50%;
                  overflow: hidden;
                  box-shadow: 0 1px 10px #eee;
                  margin-right: 20px;
                  img{
                    width: 100%;
                    height: 100%;
                  }
                }
                &-right{
                  vertical-align: top;
                  display: inline-block;
                  font-size: 22px;
                  color: #999;
                  .name{
                    color: #333;
                    font-weight: bold;
                    font-size: 26px;
                    line-height: 36px;
                    margin-bottom: 4px;
                  }
                }
              }
              .answer-info{
                margin: 20px 0;
                color: #333;
                font-size: 26px;
                line-height: 40px;
              }
              .answer-operate{
                text-align: right;
                .btn{
                  display: inline-block;
                  margin-left: 50px;
                  padding-top: 40px;
                  em{
                    display: inline-block;
                    width: 28px;
                    height: 26px;
                    vertical-align: -2px;
                    margin-right: 10px;
                    &.comment{
                      background:url(https://img.wifenxiao.com/h5-wfx/images/item/question/icon_comment.png) bottom no-repeat;
                      background-size:100% 100%;
                    }
                    &.zan{
                      background:url(https://img.wifenxiao.com/h5-wfx/images/item/question/icon_zan.png) bottom no-repeat;
                      background-size:100% 100%;
                    }
                    &.zan2{
                      background:url(https://img.wifenxiao.com/h5-wfx/images/item/question/icon_zan2.png) bottom no-repeat;
                      background-size:100% 100%;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    .comment-bottom{
      height: 108px;
      position: fixed;
      width: 100%;
      max-width: 750px;
      background: #fff;
      bottom: 0;
      left: 0;
      font-size: 0;
      padding: 0 25px;
      .input-area{
        width: calc(100vw - 230px);
        display: inline-block;
        height: 76px;
        background: #F7F7F7;
        padding: 25px;
        border-radius: 40px;
        margin-top: 16px;
        margin-right: 20px;
        input{
          font-size: 26px;
          background: #F7F7F7;
          width: 100%;
          padding: 0 10px;
        }
      }
      .btn-area{
        display: inline-block;
        .btn{
          width: 160px;
          height: 76px;
          line-height: 76px;
          color: #fff;
          background: #FD4C56;
        }
      }
    }
  }
</style>
